// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using System;
using System.Collections.Generic;
using System.Reflection;
using ValidationAspects.Sdk;

namespace ValidationAspects.Core
{
	public static class TypeExtensions
	{
		// this returns all properties including private properties in base classes, which FlattenHierachy does not
		public static IEnumerable<PropertyInfo> GetAllProperties(this Type type)
		{
			Enforce.IsNotNull(type, "type");

			do
			{
				foreach (PropertyInfo propertyInfo in
					type.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
				{
					yield return propertyInfo;
				}

				type = type.BaseType;
			} while (type != null);
		}
	}
}